package CtrLayer;
import ModelLayer.*;

/**
 * Write a description of class PersonCtr here.
 * 
 * @author (Frederik, Simon, Claus, Minh, Nichlas, Nikolai) 
 * @version (06-11-2014)
 */
public class PersonCtr
{
    // instance variables
    private PersonCon pCon;

    /**
     * Constructor for objects of class PersonCtr
     */
    public PersonCtr()
    {
        // initialise instance variables
        pCon = PersonCon.getInstance();
    }
    
    /**
     * Metode til at lave ny klasse Person og dernæst oprette objektet Person
     */
    public void createPerson(String name, String address, String postalCode, String city, String phone)
    {
        Person p = new Person(name, address, postalCode, city, phone);
        pCon.addPerson(p);
    }
    
    /**
     * En returmetode for person
     * @return en person ud fra personens telefonnummer 
     */
    public Person findPerson(String phone)
    {
        return pCon.findPerson(phone);
    }
    
    /**
     * En metode til at updatere en persons informationer
     * @param p variablen af klassen Person
     * @param name setter navn
     * @param address setter address
     * @param postalCode setter postalCode
     * @param city setter city
     * @param phone setter phone
     */
    public void updatePerson(String currPhone, String name, String address, String postalCode, String city, String phone)
    {
        Person p = findPerson(currPhone);
        p.setName(name);
        p.setAddress(address);
        p.setPostalCode(postalCode);
        p.setCity(city);
        p.setPhone(phone);
    }
    
    /**
     * En metode til at slette en person
     * @param p er værdien der skal slettes  
     */
    public void deletePerson(Person p)
    {
        pCon.deletePerson(p);
    }
    
    public PersonCon getPCon()
    {
        return pCon;
    }
    
    public Loan findLoan(String id)
    {
        return pCon.findLoan(id);
    }

}
